package com.samphanie.auiu.demo.tab

import android.graphics.BitmapFactory
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.samphanie.auiu.R
import com.samphanie.auiu.library.util.AuiuDisplayUtil
import com.samphanie.auiu.ui.tab.bottom.AuiuTabBottomInfo
import com.samphanie.auiu.ui.tab.bottom.AuiuTabBottomLayout

class AuiuTabBottomDemoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_auiu_tab_bottom_demo)

        initTabBottom()
    }

    private fun initTabBottom() {
        val auiuTabBottomLayout: AuiuTabBottomLayout = findViewById(R.id.auiu_tab_layout)
        // auiuTabBottomLayout.setTabAlpha(0.85f)
        val bottomInfoList: MutableList<AuiuTabBottomInfo<*>> = ArrayList()

        val homeInfo = AuiuTabBottomInfo(
            "首页",
            "fonts/iconfont.ttf",
            getString(R.string.if_home),
            null,
            "#ff656667",
            "#ffd44949"
        )

        val infoRecommend = AuiuTabBottomInfo(
            "收藏",
            "fonts/iconfont.ttf",
            getString(R.string.if_recommend),
            null,
            "#ff656667",
            "#ffd44949"
        )

//        val infoCategory = AuiuTabBottomInfo(
//            "分类",
//            "font/iconfont.ttf",
//            getString(R.string.if_category),
//            null,
//            "#ff656667",
//            "#ffd44949"
//        )

        val bitmap = BitmapFactory.decodeResource(resources, R.drawable.jiahao, null)
        val selectBitmap = BitmapFactory.decodeResource(resources, R.drawable.select_jiahao, null)
        val infoCategory = AuiuTabBottomInfo<String>(
            "分类",
            bitmap,
            selectBitmap
        )

        val infoChat = AuiuTabBottomInfo(
            "推荐",
            "fonts/iconfont.ttf",
            getString(R.string.if_chat),
            null,
            "#ff656667",
            "#ffd44949"
        )

        val infoProfile = AuiuTabBottomInfo(
            "我的",
            "fonts/iconfont.ttf",
            getString(R.string.if_profile),
            null,
            "#ff656667",
            "#ffd44949"
        )

        bottomInfoList.add(homeInfo)
        bottomInfoList.add(infoChat)
        bottomInfoList.add(infoCategory)
        bottomInfoList.add(infoRecommend)
        bottomInfoList.add(infoProfile)
        auiuTabBottomLayout.inflateInfo(bottomInfoList)

        auiuTabBottomLayout.addTabSelectedChangeListener { _, _, nextInfo ->
            Toast.makeText(this@AuiuTabBottomDemoActivity, nextInfo.name, Toast.LENGTH_SHORT).show()
        }

        auiuTabBottomLayout.defaultSelected(homeInfo)
        // 改变某个tab的高度  隐藏tabName
        val tabBottom = auiuTabBottomLayout.findTab(bottomInfoList[2])
        tabBottom?.apply {
            resetHeight(AuiuDisplayUtil.dp2px(56f, resources))
            showTabNameView(false)
        }
    }
}